var express = require("express");
const Result = require("../../utils/result");
const { asyncFun } = require("../../middleware/async");
var router = express.Router();

const EduService = require("./protal.service");

// 获取分类
router.get(
  "/api/blog/types",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getTypes(req.query);
    new Result(data, "成功").success(res);
  })
);

// 获取文章列表
router.get(
  "/api/blog/mds",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getMds(req.query);
    new Result(data, "成功").success(res);
  })
);

// 获取文章内容
router.get(
  "/api/blog/md/:slug",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getMdBySlug(req.params);
    new Result(data, "成功").success(res);
  })
);

// 获取文章评论
router.get(
  "/api/blog/:aid/comments",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getComments(req.params, req.query);
    new Result(data, "成功").success(res);
  })
);

// 添加评论
router.post(
  "/api/blog/:aid/comment",
  asyncFun(async function (req, res, next) {
    const data = await EduService.postComment(req.params, req.body);
    new Result(data, "评论成功").success(res);
  })
);

module.exports = router;
